var app = getApp()
Page({


  data: {
    items: [],
    sum: 0,
    checked: 0,
    isPoint: false,
    PointItem: [],
    touchEnd: 0,
    touchStart: 0,
    checked: 0,
    isAll: false,
  },

  //选中后函数
  PointTap: function (e) {
    var postId = e.currentTarget.dataset.index
    let that = this
    let items = this.data.items
    items[postId].isPoint1 = !items[postId].isPoint1
    var i
    var a = 0
    var item_post = []
    var PointItem = []
    for (i = 0; i < this.data.sum; i++) {
      if (items[i].isPoint1 == true) {
        a++;
        item_post.push(items[i].nameValue)
        PointItem.push(items[i])
      }
    }
    that.setData({
      items: items,
      checked: a,
      name: item_post,
      PointItem: PointItem
    })
  },

  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '报名名单'
    })
    var a = 0
    var i
    var items = app.globalData.data
    var item = []
    for (i = 0; i < app.globalData.sum; i++) {
      if (items[i].isPass1 == 1 && items[i].isPass2 == 1  && items[i].isOut == 0) {
        //判断是否被第一志愿淘汰
        if (items[i].isUsed1 == 0) {
          //判断是否发送面试短信
          item.push(items[i])
          a++
        }
      } 
       if (items[i].isPass1 == 0 && items[i].isPass2 == 1 && items[i].isOut == 1) {
        //判断是否被第二志愿淘汰
        if (items[i].isUsed1 == 0) {
          //判断是否发送面试短信
          item.push(items[i])
          a++
        }
      }
    }
    console.log(item)
    this.setData({
      items: item,
      sum: a
    })
  },


  OnatAllTap: function (e) {
    var that = this
    var items = this.data.items
    var i
    var a = 0
    var PointItem = []
    for (i = 0; i < this.data.sum; i++) {
      if (that.data.isAll == false) {
        if (items[i].isPoint1 == false) {
          items[i].isPoint1 = !items[i].isPoint1
        }
      } else {
        if (items[i].isPoint1 == true) {
          items[i].isPoint1 = !items[i].isPoint1
        }
      }
      if (items[i].isPoint1 == true) {
        a++
        PointItem.push(items[i])
      }
    }
    that.setData({
      isAll: !this.data.isAll,
      items: items,
      checked: a,
      PointItem: PointItem
    })
  },

  OninterviewTap: function (e) {
    wx.redirectTo({
      url: '/pages/message/message?id=' + 0,
    })
    var that = this

    app.globalData.checked = that.data.checked
    app.globalData.list = this.data.PointItem
  
  },
  touchStart: function (e) {
    var that = this;
    that.setData({
      touchStart: e.timeStamp
    })
  },

  touchEnd: function (e) {
    var that = this;
    that.setData({
      touchEnd: e.timeStamp
    })
  },

  pressTap: function (e) {
    var postid = e.currentTarget.dataset.index
    console.log(postid)
    var that = this;
    var touchTime = that.data.touchStart - that.data.touchEnd;
    if (touchTime >= 600) { //自定义长按时长，单位为ms
      wx.navigateTo({
        url: '/pages/mark_2/mark_2?id=' + postid,
      })
      app.globalData.pass = this.data.items
      that.setData({
        touchEnd: 0,
        touchStart: 0
      })
    } if (touchTime < 600) {
      that.setData({
        touchEnd: 0,
        touchStart: 0
      })
    }
  },



})